
	var WebPadImage = new Array();
	var WebPad_idx = 0;
	var WebPad_atu = 0;
	var WebPad_load = 0;
	var WebPad_wcenter;
	var WebPad_wwidth;
	var WebPad_ww;
	var WebPad_wc;
	function mouseDownHandler(evt){
		if(WebPad_load == 1)
			WebPadImage[WebPad_atu].mouseDownHandler(evt);
	}
	function mouseDownHandler2(x,y){
		if(WebPad_load == 1)
			WebPadImage[WebPad_atu].mouseDownHandler2(x,y);
	}
	function mouseupHandler(evt){
		if(WebPad_load == 1)
			WebPadImage[WebPad_atu].mouseupHandler(evt);
	}
	function mouseupHandler2(evt){
		if(WebPad_load == 1)
			WebPadImage[WebPad_atu].mouseupHandler2();
	}
	function mousemoveHandler(evt){
		if(WebPad_load == 1)
			WebPadImage[WebPad_atu].mousemoveHandler(evt);
		WebPad_ww = WebPadImage[WebPad_atu].ww;
		WebPad_wc = WebPadImage[WebPad_atu].wc;
	}
	function mousemoveHandler2(x, y){
		if(WebPad_load == 1){
			WebPadImage[WebPad_atu].mousemoveHandler2(x,y);
			WebPad_ww = WebPadImage[WebPad_atu].ww;
			WebPad_wc = WebPadImage[WebPad_atu].wc;
		}
	}
	function changeLevelImage(id){
		WebPad_atu = id;
		WebPadImage[WebPad_atu].genImage();
	}
	function addImage(uri, elem){
		WebPadImage[WebPad_idx] = new webpad();
		WebPadImage[WebPad_idx].canvasElementId = elem;
		WebPadImage[WebPad_idx].loadDicom(uri);
		WebPad_wcenter = WebPad_wc = WebPadImage[WebPad_idx].wc; 
		WebPad_wwidth = WebPad_ww = WebPadImage[WebPad_idx].ww;
		WebPad_idx = WebPad_idx +1
		WebPad_atu = WebPad_idx -1;
		WebPad_load = 1;
	}
	function moveCamada(n){
		if (WebPad_load == 0) return;
		if ((WebPad_atu + n) < WebPad_idx && (WebPad_atu + n) > -1){
			WebPad_atu = WebPad_atu + n;
			WebPadImage[WebPad_atu].lookupObj.setWindowingdata(WebPad_wc,WebPad_ww);	
			WebPadImage[WebPad_atu].genImage();
		}
	}

	function reset(){
		WebPadImage[WebPad_atu].lookupObj.setWindowingdata(WebPad_wcenter,WebPad_wwidth);
		WebPad_wc = WebPad_wcenter; 
		WebPad_ww = WebPad_wwidth;
		WebPadImage[WebPad_atu].genImage();
	}

	function applyBrilho(n){
		WebPad_wc = WebPadImage[WebPad_atu].wc = WebPadImage[WebPad_atu].wc + (n*10);
		WebPadImage[WebPad_atu].lookupObj.setWindowingdata(WebPad_wc,WebPad_ww);
		WebPadImage[WebPad_atu].genImage();
	}
	function applycontraste(n){
		WebPad_ww = WebPadImage[WebPad_atu].ww = WebPadImage[WebPad_atu].ww + (n*10);
		WebPadImage[WebPad_atu].lookupObj.setWindowingdata(WebPad_wc,WebPad_ww);		
		WebPadImage[WebPad_atu].genImage();
	}
	function showHUvalueTeste(x, y) {
		var hupanelx = document.getElementById("testx");
		var hupanely = document.getElementById("testy");
		hupanelx.innerHTML = x;
		hupanely.innerHTML = y;
	}
	function showHUvalueTeste2(x, y) {
		var hupanelx = document.getElementById("test2x");
		var hupanely = document.getElementById("test2y");
		hupanelx.innerHTML = x;
		hupanely.innerHTML = y;
	}
	function getPosicaoElemento(elemID){
	    var offsetTrail = document.getElementById(elemID);
	    var offsetLeft = 0;
	    var offsetTop = 0;
	    while (offsetTrail) {
	        offsetLeft += offsetTrail.offsetLeft;
	        offsetTop += offsetTrail.offsetTop;
	        offsetTrail = offsetTrail.offsetParent;
	    }
	    if (navigator.userAgent.indexOf("Mac") != -1 && 
	        typeof document.body.leftMargin != "undefined") {
	        offsetLeft += document.body.leftMargin;
	        offsetTop += document.body.topMargin;
	    }
	    return {left:offsetLeft, top:offsetTop};
	}
	function onmouseWheel(evt){
		if(evt.wheelDelta > 0)
			moveCamada(1);
		else
			moveCamada(-1);
	}
